//针对数组中的对象进行去重
export const _uniqueObject = (sortedArray) => {
  let res = [];
  let seen = {};
  for (let i = 0, len = sortedArray.length; i < len; i++) {
    // 如果是第一个元素或者相邻的元素不相同
    if (!i || seen.name !== sortedArray[i].name) {
      res.push(sortedArray[i]);
    }
    seen = sortedArray[i];
  }
  return res;
};

// 对JavaScript数组中的对象进行排序(依据某个字段)
export const sortObjectsByKey = (targetArray) => {
  targetArray.sort(function (a, b) {
    let val1 = a.name;
    let val2 = b.name;
    if (val1 < val2) {
      return -1;
    } else if (val1 > val2) {
      return 1;
    } else {
      return 0;
    }
  });
};
